package com.gruppsex.trainingdairy;

import java.util.ArrayList;
import java.util.Calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class DayPassActivity extends Activity {
	ArrayList<String> activitys = new ArrayList<String>();
	ArrayList<Integer> id = new ArrayList<Integer>();
	private ListView listView;
	private ArrayAdapter<String> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		overridePendingTransition(R.anim.fadein, R.anim.fadeout);
		setContentView(R.layout.daypass);
		Calendar c = Calendar.getInstance();
		int day = c.get(c.DATE);
		int month = c.get(c.MONTH);
		int year = c.get(c.YEAR);
		String date = day + "-" + (month + 1) + "-" + year;
		activitys.clear();
		DataBaseHelper dbHelper = new DataBaseHelper(this);
		dbHelper.openDataBase();
		activitys = dbHelper.getDayPass(date);
		id = dbHelper.getDayPassID(date);
		dbHelper.close();
		adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, activitys);
		listView = (ListView) findViewById(R.id.listViewGetActivities);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent = new Intent(getApplicationContext(),
						ActivityDesc.class);
				String selectedActivity = (String) listView
						.getItemAtPosition(position);
				intent.putExtra("Activity.daypass", selectedActivity);
				intent.putExtra("Activity.ID", DayPassActivity.this.id.get(position));
				
				startActivity(intent);
				adapter.remove((String) listView.getItemAtPosition(position));
				adapter.notifyDataSetChanged();
			}
		});
	}
}
